var webpack = require('webpack');
// var path = require('path');
var ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = {
    // debug: true,
    // devtool: '#cheap-module-eval-source-map',
    // devtool: '#cheap-module-source-map',//no encode error
    // devtool: '#eval-source-map',
    // devtool: '#source-map',//slow,no encode error
    // devtool: '#hidden-source-map',//slow inline
    // devtool: '#inline-source-map',//slow
    // context: path.join(__dirname, 'app'),

    entry: [
        './app/js/app.main.js'
    ],

    output: {
        // path: '/app',
        // publicPath: '/js/',
        filename: 'app.bundle.js'
    },

    module: {
        loaders: [{
            test: /\.vue$/,
            loader: 'vue',
            exclude: /node_modules/
        }, {
            test: /\.js$/,
            exclude: /node_modules/,
            query: {
                cacheDirectory: true,
                presets: ['es2015', 'stage-0'],
                plugins: ['transform-runtime']
            },
            loader: 'babel'
        }, {
            test: /\.js$/,
            loader: 'babel',
            query: {
                cacheDirectory: true,
                presets: ['es2015', 'stage-0'],
                plugins: ['transform-runtime']
            },
            exclude: /node_modules/
        }, {
            test: /\.(png|jpg|gif)$/,
            loader: 'url',
            query: {
                limit: 10*1024, //10KB
                name: 'img/[name].[ext]'
            },
            exclude: /node_modules/
        }]
    },
    vue: {
        autoprefixer: {
            browsers: ['last 2 versions', 'iOS >= 7', 'Android >= 4']
        },
        loaders: {
            sass: ExtractTextPlugin.extract(['css?minimize!sass'])
            // sass: ExtractTextPlugin.extract(['css!sass'])
        }
    },

    plugins: [
        new webpack.DefinePlugin({
            "process.env": {
                NODE_ENV: "production"
            }
        }),
        new webpack.optimize.OccurenceOrderPlugin(),
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false
            }
        }),
        new ExtractTextPlugin("app.bundle.css"),
        //Provide global variables, used in the module without having to introduce
        new webpack.ProvidePlugin({
            VueTouch: "vue-touch",
            VueResource: "vue-resource",
        })
    ]
};
